<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page import="com.iMusic.businessLogicLayer.Account" %>
<%@ page import="com.iMusic.businessLogicLayer.Product" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>iMusic</title>

<script>
function validateAddToCart()
{
	var account = request.getSession().getAttribute("Account");
	if (account==null)
  	{
  		alert("Please login before you add product to your cart.");
  		return false;
  	}
}
</script>

</head>
<body>
<%
String error=request.getParameter("error");
if(error==null || error=="null"){
 error="";
}

String error2 = (String) request.getSession().getAttribute("Error");
if(error2==null || error2=="null"){
	 error2="";
	}


%>
<%
if (!error2.equals("")) {
%>
	<div style="text-align: right; color: rgb(255, 0, 0);"><%=error2%></div>
<%
}
%>	



<table style="text-align: left; width: 100%; height: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; width: 600px;"><br>


	<div style="vertical-align: middle; text-align: center;">
	Search for Products: 
	<form style="vertical-align: middle; text-align: center; " target="_top" action="SearchProduct" method="post" name="Search" ">
		<input size="50" name="query" autofocus>&nbsp;
		<input name="searchImg" alt="" title="Search!" src="images/Search-icon.png" value=""
				type="image" height="20" width="20">
	</form>
	</div>
	
	<br>
	
	<c:if test="${ProductList.size() > 0}">
		<div style="vertical-align: middle; text-align: center;">
		<i>${ProductList.size()} Product(s) found.<i></i> <br><br>
		</div>
	</c:if>
	<c:if test="${ProductList.size() == 0}">
		<div style="margin-left: 240px;">
		<i>No products matching your selection were found.</i> <br><br>
		</div>
	</c:if>
	
	<c:forEach items="${ProductList}" var="prod">
	            <b> ${prod.getName()}</b>&nbsp(${prod.getTypeName()})&nbsp<br>
	            <i>${prod.getCategoryName()}</i><br>
	            Price: <fmt:formatNumber value="${prod.getPrice()}" type="currency"/><br>
	            <c:if test="${prod.getUnitsInStock() >= 0}"> 
	            	In Stock: ${prod.getUnitsInStock()} units<br>
	            </c:if>
	            <form style="vertical-align: middle; text-align: left; " target="_top" action="AddToCart" method="post" name="AddToCart" onsubmit="return validateAddToCart();">
	            <input type="hidden" name="ProductId" value="${prod.getProductId()}" />
				<input value="Add To Cart" type="submit">
				</form>
	            <br>
	</c:forEach>

</td>
<td style="vertical-align: top; text-align: left; width: 150px;"><br>

	
	<c:if test="${Cart != null }">
		<b>Cart</b><br>
		${Cart.size()} product(s)<br>
		Subtotal: <fmt:formatNumber value="${Cart.calculateSubtotal()}" type="currency"/><br>
		<a href="cartFS.jsp" target="_top">View Cart</a>&nbsp;
		<br>
		<c:if test="${Account == null}">
		 <form style="vertical-align: middle; " target="_top" action="checkoutFS.jsp" method="post" name="Checkout" onSubmit="return validateCheckout();">
			<input value="Checkout" type="submit" disabled>
			<br>
			<i>You must be logged in to checkout.</i>
		</form>
		
		<a href="feedbackFS.jsp" target="_top">Feedback!</a>&nbsp;
		
		</c:if>
		<c:if test="${Account != null}">
		 <form style="vertical-align: middle; " target="_top" action="checkoutFS.jsp" method="post" name="Checkout" onSubmit="return validateCheckout();">
			<input value="Checkout" type="submit">
		</form>
		
		<a href="feedbackFS.jsp" target="_top">Feedback!</a>&nbsp;
		</c:if>
	</c:if>
	<c:if test="${Cart == null }">
		<b>Cart</b><br>
		<i>Empty</i><br>
		Subtotal: $0.00<br>
		<font color="gray"><i>View Cart</i></font>&nbsp;
		<br>
	    <form style="vertical-align: middle; " target="_top" action="Checkout" method="post" name="Checkout">
			<input value="Checkout" type="submit" disabled>
		</form>
		<c:if test="${Account == null}">
			<font color="gray"><i>Feedback!</i></a>&nbsp;
		</c:if>
		
		<c:if test="${Account != null}">
			<a href="feedbackFS.jsp" target="_top">Feedback!</a>&nbsp;
		</c:if>
		
	</c:if>
	<br>
						
</td>
</tr>
</tbody>
</table>




</tr>

</body>
</html>